<?php


namespace app\general\utils;



use Illuminate\Support\Str;

class ConversionUtils
{
    public static function isHttps()
    {
        return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ;
    }

    public static function getPre(){
        return static::isHttps()?'https://':'http://';
    }
    /**
     * 驼峰转换为下划线
     * @param $data
     * @return mixed
     */
    public static function humpToUnderscore($data): array
    {
        $newParameters = [];
        if ($data) {
            foreach ($data as $key => $value) {
                if (!is_int($key)) {
                    if (is_array($value)) {
                        $newParameters[\Illuminate\Support\Str::snake($key)] = static::humpToUnderscore($value);
                    } else {
                        $newParameters[Str::snake($key)] = $value;
                    }
                } else if (is_array($value)) {
                    $newParameters[$key] = static::humpToUnderscore($value);
                } else {
                    $newParameters[$key] = $value;
                }
            }
        }
        return $newParameters;
    }

    /**
     * 下划线转换为驼峰
     * @param $data
     * @return mixed
     */
    public static function underscoreToHump($data): array
    {
        $newParameters = [];
        if ($data) {
            foreach ($data as $key => $value) {
                if (!is_int($key)) {
                    if (is_array($value)) {
                        $newParameters[Str::camel($key)] = static::underscoreToHump($value);
                    } else {
                        $newParameters[Str::camel($key)] = $value;
                    }
                } else if (is_array($value)) {
                    $newParameters[$key] = static::underscoreToHump($value);
                } else {
                    $newParameters[$key] = $value;
                }
            }
        }
        return $newParameters;
    }

}